﻿<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Signup extends CI_Controller {
	function index()
	{
		$data['error'] ='display: none;';
		
		if($this->session->userdata('email') || $this->session->userdata('logged'))
		{
			redirect('admin_home',$data);
		}
		else 
		{
			$this->form_validation->set_rules('email','Email','trim|required|xss_clean|valid_email');
			$this->form_validation->set_rules('password','Mot de passe','trim|required|xss_clean');	
			if($this->form_validation->run())
			{
				$this->load->model('admin_model');
				if($this->admin_model->check_id($this->input->post('email'),$this->input->post('password')))
				{
					$data = array('login'=>$this->input->post('email'), 'logged'=>TRUE);
					$this->session->set_userdata($data);
					redirect('admin_home',$data);
				}	
				else 
				{
					$data['style'] ='height: 35px;';	
					$data['error'] ='display: block;';
					
				}
				
			}
		}	
		
		$this->load->view('admin/signup',$data);
	}
	
}		
?>